﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace ado.net
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection sqlconnect = new SqlConnection("Data Source=.;Initial Catalog=StudentCourse;Integrated Security=True");
                sqlconnect.Open();
                string strSQL = "select Sno,Sname from Student";
                SqlCommand sqlcommand = new SqlCommand(strSQL, sqlconnect);
                SqlDataReader sqldatareader = sqlcommand.ExecuteReader();
                string strMsg = "";
                while (sqldatareader.Read())
                {
                    string strsno = (string)sqldatareader["sno"];
                    string strsname = (string)sqldatareader["sname"];
                    strMsg = strMsg + "sno:" + strsno + "sname:" + strsname + "\n";
                }
                MessageBox.Show(strMsg);

            }
            catch (Exception ex)
            { MessageBox.Show(ex.ToString()); }


         
        }
    }
}
